package com.wzt.lianfirecontrol.adapter.yuyueweibao;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wzt.lianfirecontrol.R;
import com.wzt.lianfirecontrol.adapter.BaseRecyclerAdapter;
import com.wzt.lianfirecontrol.bean.recode.function.yuyueweibao.WeiBaoPersonModel;

public class ChooseWeiBaoPersonAdapter extends BaseRecyclerAdapter<WeiBaoPersonModel> {

    private Context context;

    private String userId = "";

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public ChooseWeiBaoPersonAdapter(Context context) {
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_yuyueweibao_person, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int RealPosition, WeiBaoPersonModel data) {
        setMyData((MyViewHolder)viewHolder, data);
    }

    private class MyViewHolder extends RecyclerView.ViewHolder{
        private ImageView iv_select_flag;
        private TextView tv_person_name;
        private TextView tv_person_phone;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            initMyView(this, itemView);
        }
    }

    private void initMyView(MyViewHolder myViewHolder, View itemView) {
        myViewHolder.iv_select_flag = itemView.findViewById(R.id.iv_select_flag);
        myViewHolder.tv_person_name = itemView.findViewById(R.id.tv_person_name);
        myViewHolder.tv_person_phone = itemView.findViewById(R.id.tv_person_phone);
    }

    private void setMyData(MyViewHolder viewHolder, WeiBaoPersonModel data) {
        if (userId.equals(data.getUserId())){
            viewHolder.iv_select_flag.setImageResource(R.mipmap.icon_single_select);
        }else {
            viewHolder.iv_select_flag.setImageResource(R.mipmap.icon_single_unselect);
        }
        viewHolder.tv_person_name.setText(data.getRealName());
        viewHolder.tv_person_phone.setText(data.getPhone());
    }
}
